
Page({
  data: {
    res:"",
    prevID:"",
    obj:"",
    obj1:"",
    detail:"",
    playStates:{}
  },

  onLoad: function (options) {
    let {id} = options;
    let url = `http://192.168.4.18:3000/playlist/detail?id=${id}`;
    wx.request({
      url,
      data: {},
      header: {'content-type':'application/json'},
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: (res)=>{
        // console.log(id);
        var playlists = res.data.playlist;
        // console.log(playlists);
          
          var obj ={}
          if(playlists.playCount>=100000000){
            playlists.playCount = Math.floor(playlists.playCount/100000000)+"亿"
          }else if(playlists.playCount>=10000){
            playlists.playCount = Math.floor(playlists.playCount/10000)+"万"
          }

          if(playlists.name.length>8){
            playlists.name = playlists.name.slice(0,8)+"..."
          }
           
          obj.name = playlists.name;
          obj.id = playlists.id;
          obj.coverImgUrl = playlists.coverImgUrl;
          obj.playCount = playlists.playCount;

          obj.subscribedCount = playlists.subscribedCount;
          obj.commentCount = playlists.commentCount;
          obj.shareCount = playlists.shareCount;
          // console.log(obj.name);
          // console.log(obj.id);
          console.log(obj.playCount);
          // console.log(obj.coverImgUrl);
         
          
         
            var obj1={};
            /* if(playlists.creator.signature.length>12){
              playlists.creator.signature = playlists.creator.signature.slice(0,12)+"..."
            } */
            obj1.Cnickname = playlists.creator.nickname;
            obj1.CavatarUrl = playlists.creator.avatarUrl;
            obj1.Csignature = playlists.creator.signature;
            // console.log(obj1);
            // console.log(obj1.Cnickname);
          

          var tracks = res.data.playlist.tracks;
          var detail = [];
          tracks.forEach(item=>{
            var obj2={};

            function handleTime(value){
              if(value<10){
                  return "0"+value;
              }
              return ""+value;
          }
            var seconds = Math.floor(item.dt/1000);
            var minutes =handleTime(Math.floor(seconds/60));
            seconds = handleTime(seconds%60);
            var sum = minutes+":"+seconds;
            
            obj2.Tname = item.name;
            obj2.id = item.id;
            obj2.sum = sum;
            obj2.TalName = item.al.name;
            obj2.TalUrl = item.al.picUrl;
            detail.push(obj2)
          })
          // console.log(detail[0].TalName);
          console.log(detail);
        

        this.setData({
          obj,
          obj1,
          detail
        })
      }
    });
  },

    handleClick(event){
    let id = event.currentTarget.dataset.id;
    let playStates = this.data.playStates;

    if(id !=this.data.prevID){
      playStates[id] = true;
      for(let key in playStates){
        if(key !=id){
          playStates[key] = false;
        }
      }
      this.setData({
        playStates,
        prevID:id
      })
    }else{
      playStates[id] = !playStates[id];
      this.setData({
        playStates
      })
    }
  },
  handleToggle(event){
    let {id} = event.currentTarget.dataset;
  } 
})